I'm creating a custom component (derived from TCustomCategoryPanelGroup) and performing some custom draw operations. I want to handle when Themes are enabled and draw text appropriately.
Here is a snippet of some code I have in a draw function:
int theBaseDrawFlags = DT_EXPANDTABS | DT_SINGLELINE | DT_VCENTER | DT_LEFT;
theBaseDrawFlags = DrawTextBiDiModeFlags( theBaseDrawFlags );
if ( TCustomCategoryPanelGroup::hsThemed == PanelGroup->HeaderStyle && ThemeServices()->ThemesEnabled )
{
ThemeServices()->DrawText( ACanvas->Handle, ThemeServices()->GetElementDetails( tebNormalGroupHead ), m_CaptionTopLeft, m_TextRect, theBaseDrawFlags, 0 );
}
else
{
// Draw without themes
}
When I attempt to build this I receive the error:
Unresolved external __fastcall Themes::TThemeServices::DrawTextA(HDC__ *, Themes::TThemedElementDetails&, const System::WideString, Types::TRect&, unsigned int, unsigned int)' referenced from ....
As you can see it's looking for DrawTextA. I've looked at the Themes.hpp header and there is only a ThemeServices::DrawText function defined.
I'm not sure what's going on here. I thought perhaps that I was missing an import library, but all of the other ThemeServices functions that I use don't get link errors.
Anyone know what's going on here?
I guess you have #included some header (windows.h?) that contains something like this
#ifdef UNICODE
#define DrawText DrawTextW
#else
#define DrawText DrawTextA
#endif
You can probably put an #undef DrawText in your file to work around this. (See also Conflict with DrawText function.)
Related
#include "Simple_window.h"
#include "Graph.h"
#include <math.h>
#include <iostream>
#include <limits>
using namespace std;
int main(){
Simple_window win(Point(100,100),600,400,"Marks");
Graph_lib::Polygon poly;
bool over = true;
int n = 0;
while(over){
Marks pp("x");
pp.add(Point(300,200));
cout<<"Enter number of sides (3 or more): ";
while(!(cin>>n)){
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<"Enter number of sides (3 or more): ";
}
if(n<3){
break;
}
//Finding the angle and number of sides...
if(n%2 != 0){
//logic for polygon...
}
}else{
//logic for polygon...
}
}
poly.set_color(Color::magenta); // adjust properties of poly
win.attach (poly); // connect poly to the window
win.attach(pp);
win.wait_for_button(); // Display!
}
}
What does this program does it make n-sided polygons. After I set my polygon. I wish to reset it. After i enter the amount of sides in a polygon. I click on "next" it will ask me how many polygons again and repeat the process. Someone told me to call delete. However I'm not sure how I would type that in. As in delete poly.points? or delete polygon ? I tried a few but I kept getting errors.
My second question is on line 38. Originally I had it so If i entered a number less than 3 the program will end. But the program won't end. So i had to use break;
if(n<3){
over=false;
cout<<"why wont this end ?"<<endl;
}
boolean over is set to true. While true loop. If n < 3 over is false. thus end the program? it Wont end.
There is no need to reset the poly if you stick the declaration inside the first while loop.
while(over){
Graph_lib::Polygon poly;
...
win.wait_for_button();
}
Re: why your program won't end. Break is good enough but if you don't like using break
use continue
put the rest of the loop body in an else clause
Edit: Re: changing the title: I don't know the Simpe_Window interface: it is not part of FLTK - it is a Stroustrup creation. If it is derived from FL_Window, use label(new title).
I want to draw a line using mouse-event in Opencv in a webcam frame. I also want to erase it just like an eraser in MS-Paint.How can i do it? I dont have much idea about it. But i have this scrambled pseduo code from my head which can be completely wrong but i will write it down anyway. I would like to know how to implement it in c++.
So, i will have two three mouse event-
event 1- Mouse leftbuttonup-- this will be used to start the drawing
event 2- Mouse move -- this will be used to move the mouse to draw
event 3:- Mouse leftbuttondown-this will be used to stop the drawing.
event 4- Mouse double click - this event i can use to erase the drawing.
I will also have a drawfunction for a line such as line(Mat image,Point(startx,starty),Point(endx,endy),(0,0,255),1));
Now, i dont know how to implement this in a code format. I tried a lot but i get wrong results. I have a sincere request that please suggest me the code in Mat format not the Iplimage format. Thanks.
please find working code below with inlined explained comments using Mat ;)
Let me know in case of any problem.
PS: In main function, I have changed defauld cam id to 1 for my code, you should keep it suitable for you PC, probably 0. Good Luck.
#include <iostream>
#include <opencv\cv.h>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
class WebCamPaint
{
public:
int cam_id;
std::string win_name;
cv::VideoCapture webCam;
cv::Size frame_size;
cv::Mat cam_frame, drawing_canvas;
cv::Point current_pointer, last_pointer;
cv::Scalar erase_color, paint_color;
int pointer_size;
//! Contructor to initialize basic members to defaults
WebCamPaint()
{
cam_id = 0;
pointer_size = 5;
win_name = std::string("CamView");
current_pointer = last_pointer = cv::Point(0, 0);
erase_color = cv::Scalar(0, 0, 0);
paint_color = cv::Scalar(250, 10, 10);
}
//! init function is required to set some members in case default members needed to change.
bool init()
{
//! Opening cam with specified cam id
webCam.open(cam_id);
//! Check if problem opening video
if (!webCam.isOpened())
{
return false;
}
//! Reading single frame and extracting properties
webCam >> cam_frame;
//! Check if problem reading video
if (cam_frame.empty())
{
return false;
}
frame_size = cam_frame.size();
drawing_canvas = cv::Mat(frame_size, CV_8UC3);
//! Creating Activity / Interface window
cv::namedWindow(win_name);
cv::imshow(win_name, cam_frame);
//! Resetting drawing canvas
drawing_canvas = erase_color;
//! initialization went successful ;)
return true;
}
//! This function deals wih all processing, drawing and displaying ie main UI to user
void startAcivity()
{
//! Keep doing until user presses "Esc" from Keyboard, wait for 20ms for user input
for (char user_input = cv::waitKey(20); user_input != 27; user_input = cv::waitKey(20))
{
webCam >> cam_frame; //Read a frame from webcam
cam_frame |= drawing_canvas; //Merge with actual drawing canvas or drawing pad, try different operation to merge incase you want different effect or solid effect
cv::imshow(win_name, cam_frame); //Display the image to user
//! Change size of pointer using keyboard + / -, don't they sound fun ;)
if (user_input == '+' && pointer_size < 25)
{
pointer_size++;
}
else if (user_input == '-' && pointer_size > 1)
{
pointer_size--;
}
}
}
//! Our function that should be registered in main to opencv Mouse Event Callback
static void onMouseCallback(int event, int x, int y, int flags, void* userdata)
{
/* NOTE: As it will be registered as mouse callback function, so this function will be called if anything happens with mouse
* event : mouse button event
* x, y : position of mouse-pointer relative to the window
* flags : current status of mouse button ie if left / right / middle button is down
* userdata: pointer o any data that can be supplied at time of setting callback,
* we are using here to tell this static function about the this / object pointer at which it should operate
*/
WebCamPaint *object = (WebCamPaint*)userdata;
object->last_pointer = object->current_pointer;
object->current_pointer = cv::Point(x, y);
//! Drawing a line on drawing canvas if left button is down
if (event == 1 || flags == 1)
{
cv::line(object->drawing_canvas, object->last_pointer, object->current_pointer, object->paint_color, object->pointer_size);
}
//! Drawing a line on drawing canvas if right button is down
if (event == 2 || flags == 2)
{
cv::line(object->drawing_canvas, object->last_pointer, object->current_pointer, object->erase_color, object->pointer_size);
}
}
};
int main(int argc, char *argv[])
{
WebCamPaint myCam;
myCam.cam_id = 1;
myCam.init();
cv::setMouseCallback(myCam.win_name, WebCamPaint::onMouseCallback, &myCam);
myCam.startAcivity();
return 0;
}
I want to draw text to a DirectX game, so I've injected a DLL which hooks EndPaint. My logic was that since EndPaint is supposed to be the last step in the WM_PAINT operation, I could, in my hook, draw the text, and then call EndPaint myself. By doing this, I avoid the DX interface altogether.
The problem is that it is doing absolutely nothing. Here is my code.
#include <windows.h>
#include "Hooks.h"
static const TCHAR g_cszMessage[] = TEXT("utterly fantastic");
BOOL (WINAPI * _EndPaint)(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint) = EndPaint;
BOOL WINAPI EndPaintHook(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint)
{
// write message
TextOut(lpPaint->hdc, 0, 0, g_cszMessage, lstrlen(g_cszMessage));
GdiFlush();
// return original
return _EndPaint(hWnd, lpPaint);
}
BOOL APIENTRY DllMain(__in HINSTANCE hModule, __in DWORD fdwReason, __in __reserved LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (AttachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook))
{
DisableThreadLibraryCalls(hModule);
break;
}
return FALSE;
case DLL_PROCESS_DETACH:
DetachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook);
break;
}
return TRUE;
}
I know the issue isn't with my AttachHook/DetachHook functions because I've tested via message boxes and confirmed that the hooks are installed. The text simply isn't showing up.
Anyone have any idea? I don't really want to hook the DX interface. Shouldn't it work either way, since WM_PAINT is still used at the base level?
Thanks in advance.
You are better off hooking the present of DirectX and then using ID3DXFont to do some font rendering. AFAIK WM_PAINT is not used for DirectX rendering.
Can anybody help with converting an SDL_Surface object, a texture loaded from a file, into an IDirect3DTexture9 object.
I honestly don't know why you would ever want to do this. It sounds like a truly horrible idea for a variety of reasons, so please tell us why you want to do this so we can convince you not to ;).
In the meanwhile, a quick overview of how you'd go about it:
IDirect3DTexture9* pTex = NULL;
HRESULT hr = S_OK;
hr = m_d3dDevice->CreateTexture(
surface->w,
surface->h,
1,
usage,
format,
D3DPOOL_MANAGED,
&pTex,
NULL);
This creates the actual texture with the size and format of the SDL_Surface. You'll have to fill in the usage on your own, depending on how you want to use it (see D3DUSAGE). You'll also have to figure out the format on your own - you can't directly map a SDL_PixelFormat to a D3DFORMAT. This won't be easy, unless you know exactly what pixel format your SDL_Surface is.
Now, you need to write the data into the texture. You can't use straight memcpy here, since the SDL_Surface and the actual texture may have different strides. Here's some untested code that may do this for you:
HRESULT hr;
D3DLOCKED_RECT lockedRect;
// lock the texture, so that we can write into it
// Note: if you used D3DUSAGE_DYNAMIC above, you should
// use D3DLOCK_DISCARD as the flags parameter instead of 0.
hr = pTex->LockRect(0, &lockedRect, NULL, 0);
if(SUCCEEDED(hr))
{
// use char pointers here for byte indexing
char* src = (char*) surface->pixels;
char* dst = (char*) lockedRect->pBits;
size_t numRows = surface->h;
size_t rowSize = surface->w * surface->format->BytesPerPixel;
// for each row...
while(numRows--)
{
// copy the row
memcpy(dst, src, rowSize);
// use the given pitch parameters to advance to the next
// row (since these may not equal rowSize)
src += surface->pitch;
dst += lockedRect->Pitch;
}
// don't forget this, or D3D won't like you ;)
hr = pTex->UnlockRect(0);
}
I'm trying to read 3D models which were created for a DirectX applications, which are defined in the following way :
In the file header, the Flexible Vertex Format (FVF) of the mesh is given (actually, I have any combinations of D3DFVF_{XYZ,DIFFUSE,NORMAL,TEX1,TEX2} in the meshes I tested)
Then, n vertices are given in a linear pattern, with the fields presents according to the FVF.
However, I do not know the order of these fields. The logic would be that it is defined somewhere in DirectX documentation, but I was unable to find it. For example, which of these two structures is correct with FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL (C syntax, but this problem applies to every language) ?
// This one ?
struct vertex1
{
D3DVERTEX pos;
DWORD color;
D3DVERTEX normal;
};
// Or this one ?
struct vertex2
{
D3DVERTEX pos;
D3DVERTEX normal;
DWORD color;
};
I would like a general answer to this question with all the possible fields (for example, XYZ before DIFFUSE before NORMAL before TEX1 before TEX2). A pointer to the right page of the documentation would be fine too as I was not able to find it :) .
I ran into the same thing myself.
I think the order of the bits is the required order. From d3d9types.h:
#define D3DFVF_RESERVED0 0x001
#define D3DFVF_POSITION_MASK 0x400E
#define D3DFVF_XYZ 0x002
#define D3DFVF_XYZRHW 0x004
#define D3DFVF_XYZB1 0x006
#define D3DFVF_XYZB2 0x008
#define D3DFVF_XYZB3 0x00a
#define D3DFVF_XYZB4 0x00c
#define D3DFVF_XYZB5 0x00e
#define D3DFVF_XYZW 0x4002
#define D3DFVF_NORMAL 0x010
#define D3DFVF_PSIZE 0x020
#define D3DFVF_DIFFUSE 0x040
#define D3DFVF_SPECULAR 0x080
#define D3DFVF_TEXCOUNT_MASK 0xf00
#define D3DFVF_TEXCOUNT_SHIFT 8
#define D3DFVF_TEX0 0x000
#define D3DFVF_TEX1 0x100
#define D3DFVF_TEX2 0x200
#define D3DFVF_TEX3 0x300
#define D3DFVF_TEX4 0x400
#define D3DFVF_TEX5 0x500
#define D3DFVF_TEX6 0x600
#define D3DFVF_TEX7 0x700
#define D3DFVF_TEX8 0x800
I'm pretty sure that the order you are looking for is:
POSITION,NORMAL,PSIZE,DIFFUSE,SPECULAR,TEX0[,TEXn...]
I wasn't able to find a definitive answer in the documentation either.
here you are
FVF (OP says the information on this page is incorrect. I dont know, didnt check if FVF positioning is correct)
Generator
Well you should be defining it as follows.
struct EitherVertex
{
float x, y, z;
DWORD col;
float nx, ny, nz
};
or
struct EitherVertex
{
D3DXVECTOR3 pos;
DWORD col;
D3DXVECTOR3 nrm;
};
(D3DVERTEX refers to an entire vertex struct and not just a 3 element vector)
Of your 2 options a lot depends on how you access those vert elements. If you are using the depreceated FVF then the second of your 2 choice is the more correct.
If however you are using Vertex Declarations then YOU define where in the struct the relevant data is and the ordering does not matter.